package rsp

import (
	"github.com/gin-gonic/gin"
	"myself/constants"
	"time"
)

// SuccessResponse 成功响应
func SuccessResponse(ctx *gin.Context, data interface{}) {
	ctx.JSON(200, ResponseData{
		Code:    constants.SuccessCode,
		Message: "SUCCESS",
		NowTs:   time.Now().Unix(),
		Data:    data,
	})
}

// FailResponse 失败响应
func FailResponse(ctx *gin.Context, message string, code ...constants.ErrorCode) {
	ctx.Header("content-type", "application/json")
	realCode := constants.FailCode
	if len(code) > 0 {
		realCode = code[0]
	}

	ctx.JSON(200, ResponseData{
		Code:    realCode,
		Message: message,
		NowTs:   time.Now().Unix(),
		Data:    make(map[string]string, 0),
	})
}
